var newsfeedView = Backbone.View.extend({
	 el: $(".mainpart"),
	 events: {'click #newsfeedarea a ' : 'showUserDetails', 'click .docappointment' : 'showdocview'} ,
	 initialize: function() {

	        this.render();
	        
	 },
	 render: function () {
		 	this.template=_.template($('#myfeed-template').html());
		    $("#recentactivities").html(this.template);
	        $('#recentactivities').slimScroll({
	            height: '100%',
	            disableFadeOut: false,
	           // width:'75%',
	            railVisible: true,
	            alwaysVisible: false
	        });
	        $('#recentactivities').slimScroll().bind('slimscroll', function(event, pos){
	            if (pos == 'bottom') {
		      		 $.msgBox({
						    title:"Yashoda Clinic",
						    content:"No more appointments!",
						    type:"info"
						});
	            }
	        }); 
	        //https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/c170.50.621.621/s160x160/306264_10151378437603439_1351471632_n.jpg
	        var hoverHTMLDoctor='<img class="s-img" src=""><p class="s-desc">Leading Hematologist in central india.</p><p class="s-desc"><span class="s-strong">Web:</span><br><a href="http://vijay.cloudfoundry.com/">http://vijay.cloudfoundry.com/</a></p><p class="s-desc"><span class="s-strong">Email:</span><br><a class="email" href="#"></a></p>';
		        $('.doctor').hovercard({
		        	detailsHTML: hoverHTMLDoctor,
		        	onHoverIn: function(){
		            	var doctorName=$(this)[0].innerText.slice(4);
		            	for(var i in jsonObj){
		            		if(doctorName == jsonObj[i].doctor.name){
		            			$('.email').text(jsonObj[i].doctor.email)
		            			if(jsonObj[i].doctor.provider=="google"){
		            				 $('.s-img').attr('src','https://profiles.google.com/s2/photos/profile/'+jsonObj[i].doctor.userid);
		            			}
		            			if(jsonObj[i].doctor.provider=="facebook"){
		            				 $('.s-img').attr('src','https://graph.facebook.com/'+jsonObj[i].doctor.userid+'/picture');
		            			}
		            			if(jsonObj[i].doctor.provider=="twitter"){
		            				 $('.s-img').attr('src','https://api.twitter.com/1/users/profile_image?user_id='+jsonObj[i].doctor.userid);
		            			}
		            			break;
		            		}
		            	}
		            	
		        	}
		        });
	        

		        var hoverHTMLPatient='<img class="s-img" src=""><p class="s-desc"><span class="s-strong">Email:</span><br><a class="email" href="#"></a></p>';
		        $('.patient').hovercard({
		        	detailsHTML: hoverHTMLPatient,
		        	onHoverIn: function(){
		            	var patientName=$(this)[0].innerText;
		            	for(var i in jsonObj){
		            		if(patientName == jsonObj[i].patient.name){
		            			$('.email').text(jsonObj[i].patient.email)
		            			if(jsonObj[i].patient.provider=="google"){
		            				 $('.s-img').attr('src','https://profiles.google.com/s2/photos/profile/'+jsonObj[i].patient.userid);
		            			}
		            			if(jsonObj[i].patient.provider=="facebook"){
		            				 $('.s-img').attr('src','https://graph.facebook.com/'+jsonObj[i].patient.userid+'/picture');
		            			}
		            			if(jsonObj[i].patient.provider=="twitter"){
		            				 $('.s-img').attr('src','https://api.twitter.com/1/users/profile_image?user_id='+jsonObj[i].patient.userid);
		            			}
		            			break;
		            		}
		            	}
		            	
		        	}
		        });
	        
		    return this;
		},
	 showUserDetails: function(){
			$("#modal_window").lightbox_me({
				centered: true, 
				onLoad: function() {
					$("#modal_window").find("input:first").focus();
				}
			});

	 },
	 showdocview: function(event){
		 var appointmentId = $(event.target).attr('appointmentid');
		 var o=CKEDITOR.instances['editor1'];
		 if (o) o.destroy();
		 CKEDITOR.replace('editor1', {});
/*		 var o=CKEDITOR.instances['appointmentcomments'];
		 if (o) o.destroy();
*/		 for(var i in jsonObj){
			 if(appointmentId== jsonObj[i].id){
				 $("#modal_form_doc1").find("label:first strong").text(jsonObj[i].patient.name+" , 35 Years");
				 $("#modal_form_doc1").find("label:first ").css({'text-align': 'center'});
				 $("#modal_form_doc1").find("fieldset:first label:nth-child(2) strong").text("Chief Complaint: "+jsonObj[i].appointmentHeadline);
				 $("#modal_form_doc1").find("fieldset:first label:nth-child(3) strong").text("History of present illness: "+jsonObj[i].appointmentComment);				 
				 $("#pasthistory").find("label:nth-child(2) strong").text("Allergies: None");
				 $("#pasthistory").find("label:nth-child(3) strong").text("Past Medical History: NA");
				 $("#pasthistory").find("label:nth-child(4) strong").text("Past Surgical History: NA");
				 break;
			 }
		 }
		//$("#examination").collapse();
		$("#patientcomplaint").collapse();
		$("#pasthistory").collapse( { closed: true } );
		$("#investigations").collapse( { closed: true } );
		$("#treatment").collapse( { closed: true } );
/*		$("input#investigationType").autocomplete({
		    source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]
		});*/

        /* $('#editor1').each(function(){
             var ckId = $(this).attr('id');*/
             //config = {};
            
        // })

         $("#doc_appointment").lightbox_me({centered: true, onLoad: function() {
			//	$("#modal_window").find("input:first").focus();
			}
         });
	 }
	 
});
var newsfeedview = new newsfeedView();


function rssfeedright(){
	var feedpointer=new google.feeds.Feed(feedurl);
	feedpointer.setNumEntries(feedlimit) ;
	feedpointer.load(displayfeedright) ;
}

function displayfeedright(result){
	var rssoutput1="<ul>";
	if (!result.error){
		var thefeeds=result.feed.entries;
		var text;
		for (var i=0; i<thefeeds.length; i++){
			text =thefeeds[i].title.length> 52?thefeeds[i].title.slice(0,50)+"..":thefeeds[i].title;
			rssoutput1+="<li><a target=\"_blank\" href='" + thefeeds[i].link + "' title=\""+thefeeds[i].title+"\">" + text + "</a></li>";
		}
			
		rssoutput1+="</ul>";
		$('#rightnewsdiv').html(rssoutput1);

	}
}

function showAppointment(date){
	alert(date);
}
/*$(document).ready(function() {
    $("#investigationType").tokenInput([
        {id: 7, name: "Ruby"},
        {id: 11, name: "Python"},
        {id: 13, name: "JavaScript"},
        {id: 17, name: "ActionScript"},
        {id: 19, name: "Scheme"},
        {id: 23, name: "Lisp"},
        {id: 29, name: "C#"},
        {id: 31, name: "Fortran"},
        {id: 37, name: "Visual Basic"},
        {id: 41, name: "C"},
        {id: 43, name: "C++"},
        {id: 47, name: "Java"}
    ]);
});*/